﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using QuanLyBanHang.QuerySQL;

namespace QuanLyBanHang
{
    public partial class frqlNhaphang : Office2007Form
    {
        ClassqlNhaphang qlnh = new ClassqlNhaphang();
        private int dong;
        public frqlNhaphang()
        {
            InitializeComponent();
        }

        private void frqlNhaphang_Load(object sender, EventArgs e)
        {
            dtgv_PN.DataSource = qlnh.ShowQLPN(0);
            dtgv_CTPN.DataSource = qlnh.ShowQLPN(3);
        }

        private void dtgv_PN_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
            try
            {
                for (int i = 0; i < dtgv_PN.RowCount; i++)
                {
                    dtgv_PN.Rows[i].Cells["cl_stt"].Value = i + 1;
                }
            }
            catch { }
        }

        private void dtgv_CTPN_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
            try
            {
                for (int i = 0; i < dtgv_CTPN.RowCount; i++)
                {
                    dtgv_CTPN.Rows[i].Cells["clct_stt"].Value = i + 1;
                }
            }
            catch { }
        }

        private void dtgv_PN_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            dong = e.RowIndex;
            dtgv_CTPN.DataSource = qlnh.ShowQLPN(4, null, null, dtgv_PN.Rows[dong].Cells["cl_mapn"].Value.ToString());
        }

        private void txtmahd_TextChanged(object sender, EventArgs e)
        {
            dtgv_PN.DataSource = qlnh.ShowQLPN(1,txtmapn.Text);
        }

        private void txtmakh_TextChanged(object sender, EventArgs e)
        {
            dtgv_PN.DataSource = qlnh.ShowQLPN(2,null,txttenncc.Text);
        }

        private void btnhuy2_Click(object sender, EventArgs e)
        {
            txtmapn.Clear();
            txttenncc.Clear();
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            DialogResult kq = MessageBox.Show("Bạn có chắc muốn xóa Hóa đơn " + dtgv_PN.Rows[dong].Cells["cl_mapn"].Value.ToString() + "  ? ", "Thông báo", MessageBoxButtons.YesNo);
             if (kq == DialogResult.Yes)
             {
                 qlnh.XoaPN(dtgv_PN.Rows[dong].Cells["cl_mapn"].Value.ToString());
                 frqlNhaphang_Load(sender, e);
             }
        }

        private void txtctmapn_TextChanged(object sender, EventArgs e)
        {
            dtgv_CTPN.DataSource = qlnh.ShowQLPN(4,null,null,txtctmapn.Text);
        }
    }
}
